<?php
/**
 * @package Admin, Model
 * @author Henrique Droog <henridroog@gmail.com>
 * @name User
 * @since 18/04/2011
 * @version 1.0
 */
class Admin_Model_User {

    protected $_role;
    protected $_ativo;
    protected $_inicio;
    protected $_password;
    protected $_name;
    protected $_id;

    public function __construct(array $options = null)
    {
        if (is_array($options)) {
            $this->setOptions($options);
        }
    }

    public function __set($name, $value)
    {
        $method = 'set' . $name;
        if (('mapper' == $name) || !method_exists($this, $method)) {
            throw new Exception('Propriedade de role inválida');
        }
        $this->$method($value);
    }

    public function __get($name)
    {
        $method = 'get' . $name;
        if (('mapper' == $name) || !method_exists($this, $method)) {
            throw new Exception('Propriedade de role inválida');
        }
        return $this->$method();
    }

    public function setOptions(array $options)
    {
        $methods = get_class_methods($this);
        foreach ($options as $key => $value) {
            $method = 'set' . ucfirst($key);
            if (in_array($method, $methods)) {
                $this->$method($value);
            }
        }
        return $this;
    }
    
    public function setRole($role)
    {
        $this->_role = $role;
        return $this;
    }

    public function getRole()
    {
        return $this->_role;
    }

    public function setAtivo($ativo)
    {
        $this->_ativo = $ativo;
        return $this;
    }

    public function getAtivo()
    {
        return $this->_ativo;
    }

    public function setInicio($inicio)
    {
        $this->_inicio = $inicio;        
        return $this;
    }

    public function getInicio()
    {
        return $this->_inicio;
    }

    public function setPassword($password)
    {
        $this->_password = md5($password);
        return $this;
    }

    public function getPassword()
    {
        return $this->_password;
    }

    public function setName($text)
    {
        $this->_name = $text;
        return $this;
    }

    public function getName()
    {
        return $this->_name;
    }

    public function setId($id)
    {
        $this->_id = (int) $id;
        return $this;
    }

    public function getId()
    {
        return $this->_id;
    }
}